package com.googlecode.gwtbb.client.shared.validation;

import com.googlecode.gwtbb.client.shared.util.HashCodeUtils;

import java.io.Serializable;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Apr 30, 2008
 */
public class FieldId implements Serializable {
	private String field;
	private int index;

	public static FieldId create(String name, int index) {
		return new FieldId(name, index);
	}

	public FieldId() {
	}

	public FieldId(String field, int index) {
		this.field = field;
		this.index = index;
	}

	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public boolean equals(Object obj) {
		if (obj instanceof FieldId) {
			FieldId other = (FieldId)obj;
			return field.equals(other.field) && index == other.index;
		}
		return false;
	}

	public int hashCode() {
		int retVal = HashCodeUtils.SEED;
		retVal = HashCodeUtils.hash(retVal, field);
		retVal = HashCodeUtils.hash(retVal, index);
		return retVal;
	}

	public String toString() {
		return field;
	}
}
